// CoachMemory.cpp

// Implementacia pamate kouca 

#include "Coach/CoachKernel.h"
//#include <string.h>
//#include <math.h>

void CoachKernel::OnPlayerParam(const PLAYER_PARAMS* pp)
{
	if(playerParams != NULL)
		delete playerParams;
	playerParams = new PLAYER_PARAMS;

	memcpy(playerParams, pp, sizeof(PLAYER_PARAMS));

	if(playerTypes != NULL)
		delete playerTypes;
	
	playerTypes = new PLAYER_TYPE[playerParams->player_types];

	// playerTypes[i] will be filled by CoachKernel::OnPlayerType
	// which is called when that info is received from server
}

void CoachKernel::OnPlayerType(int id, const PLAYER_TYPE* pt)
{
	nHeteroCounter++;
	memcpy(&playerTypes[id], pt, sizeof(PLAYER_TYPE));
}

// Simulacne parametre
void CoachKernel::OnServerParam(const SERVER_PARAMS* sp)
{
	if(serverParams == NULL)
		serverParams = new SERVER_PARAMS;

	memcpy((void*) serverParams, (void*) sp, sizeof(SERVER_PARAMS));

	// Nastavenie suradnic vlajok
	flagPos[GOAL_L] = Point(-52.5f, 0);
	flagPos[GOAL_R] = Point(52.5f, 0);

	flagPos[C] = Point(0, 0);
	flagPos[CT] = Point(0, -34);
	flagPos[CB] = Point(0, 34);
	flagPos[LT] = Point(-52.5f, -34);
	flagPos[LB] = Point(-52.5f, 34);
	flagPos[RT] = Point(52.5f, -34);
	flagPos[RB] = Point(52.5f, 34);

	flagPos[PLT] = Point(-36, -20.16f);
	flagPos[PLC] = Point(-36, 0);
	flagPos[PLB] = Point(-36, 20.16f);
	flagPos[PRT] = Point(36, -20.16f);
	flagPos[PRC] = Point(36, 0);
	flagPos[PRB] = Point(36, 20.16f);

	flagPos[GLT] = Point(-52.5f, -sp->goal_width / 2);
	flagPos[GLB] = Point(-52.5f, sp->goal_width / 2);
	flagPos[GRT] = Point(52.5f, -sp->goal_width / 2);
	flagPos[GRB] = Point(52.5f, sp->goal_width / 2);

	flagPos[TL50] = Point(-50, -39);
	flagPos[TL40] = Point(-40, -39);
	flagPos[TL30] = Point(-30, -39);
	flagPos[TL20] = Point(-20, -39);
	flagPos[TL10] = Point(-10, -39);
	flagPos[T0] = Point(0, -39);
	flagPos[TR10] = Point(10, -39);
	flagPos[TR20] = Point(20, -39);
	flagPos[TR30] = Point(30, -39);
	flagPos[TR40] = Point(40, -39);
	flagPos[TR50] = Point(50, -39);

	flagPos[BL50] = Point(-50, 39);
	flagPos[BL40] = Point(-40, 39);
	flagPos[BL30] = Point(-30, 39);
	flagPos[BL20] = Point(-20, 39);
	flagPos[BL10] = Point(-10, 39);
	flagPos[B0] = Point(0, 39);
	flagPos[BR10] = Point(10, 39);
	flagPos[BR20] = Point(20, 39);
	flagPos[BR30] = Point(30, 39);
	flagPos[BR40] = Point(40, 39);
	flagPos[BR50] = Point(50, 39);

	flagPos[LT30] = Point(-57.5f, -30);
	flagPos[LT20] = Point(-57.5f, -20);
	flagPos[LT10] = Point(-57.5f, -10);
	flagPos[L0] = Point(-57.5f, 0);
	flagPos[LB10] = Point(-57.5f, 10);
	flagPos[LB20] = Point(-57.5f, 20);
	flagPos[LB30] = Point(-57.5f, 30);

	flagPos[RT30] = Point(57.5f, -30);
	flagPos[RT20] = Point(57.5f, -20);
	flagPos[RT10] = Point(57.5f, -10);
	flagPos[R0] = Point(57.5f, 0);
	flagPos[RB10] = Point(57.5f, 10);
	flagPos[RB20] = Point(57.5f, 20);
	flagPos[RB30] = Point(57.5f, 30);
}


